package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.modles.FindDetailsModle;

/**
 * 已经没用的适配器，可是就是不想删
 * Created by lanouhn on 16/9/5.
 */
public class FindDetailsWaiAdapter extends RecyclerView.Adapter<FindDetailsWaiAdapter.MyHolder> {

    private Context mContext;
    private FindDetailsModle findDetailsModle;
    private int count;
    private FindDetailsLiAdapter liAdapter;

    public FindDetailsWaiAdapter(Context mContext, FindDetailsModle findDetailsModle) {
        this.mContext = mContext;
        this.findDetailsModle = findDetailsModle;
        this.count = findDetailsModle.getTrip_days().size() + 1;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_find_details_wai, null);
        MyHolder holder = new MyHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        if (position == 0) {
            holder.tv_zhuti.setText(findDetailsModle.getName());
            holder.tv_shijian.setText(findDetailsModle.getStart_date());
            holder.tv_tianshu.setText(findDetailsModle.getTrip_days().size() + "天");
            holder.tv_tushu.setText(findDetailsModle.getPhotos_count() + "图");
            Picasso.with(mContext).load(findDetailsModle.getFront_cover_photo_url()).into(holder.iv_datu);
            Picasso.with(mContext).load(findDetailsModle.getUser().getImage()).into(holder.iv_xiaotu);
            holder.tv_day.setVisibility(View.GONE);
            holder.ll.setVisibility(View.GONE);
        } else {
            int i = position - 1;
            holder.tv_zhuti.setVisibility(View.GONE);
            holder.tv_shijian.setVisibility(View.GONE);
            holder.tv_tianshu.setVisibility(View.GONE);
            holder.tv_tushu.setVisibility(View.GONE);
            holder.iv_datu.setVisibility(View.GONE);
            holder.iv_xiaotu.setVisibility(View.GONE);

            holder.tv_day.setVisibility(View.VISIBLE);
            holder.ll.setVisibility(View.VISIBLE);


            int day = findDetailsModle.getTrip_days().get(i).getDay();
            String string_day = day + "";
            holder.tv_day.setText("DAY" + string_day);

            RecyclerView recyclerView = new RecyclerView(mContext);
            liAdapter = new FindDetailsLiAdapter(mContext, findDetailsModle.getTrip_days().get(i));
            recyclerView.setAdapter(liAdapter);

            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
            recyclerView.setLayoutManager(linearLayoutManager);

//            View view1 = LayoutInflater.from(mContext).inflate();
//
//            TextView textView = view1.findViewById();
//
//                    textView.setText("");



            holder.ll.addView(recyclerView);

        }


    }

    @Override
    public int getItemCount() {
        //共有多少个item,就是长度
        return count;
    }


    public class MyHolder extends RecyclerView.ViewHolder {

        private ImageView iv_datu, iv_xiaotu;
        private TextView tv_zhuti, tv_shijian, tv_tianshu, tv_tushu, tv_day;
        private LinearLayout ll;

        public MyHolder(View itemView) {
            super(itemView);

            iv_datu = (ImageView) itemView.findViewById(R.id.find_details_wai_datu);
            iv_xiaotu = (ImageView) itemView.findViewById(R.id.find_details_wai_xiaotu);
            tv_zhuti = (TextView) itemView.findViewById(R.id.find_details_wai_zuti);
            tv_shijian = (TextView) itemView.findViewById(R.id.find_details_wai_shijian);
            tv_tianshu = (TextView) itemView.findViewById(R.id.find_details_wai_tianshu);
            tv_tushu = (TextView) itemView.findViewById(R.id.find_details_wai_tushu);
            tv_day = (TextView) itemView.findViewById(R.id.find_details_wai_day);
            ll = (LinearLayout) itemView.findViewById(R.id.find_details_wai_ll);
        }
    }

}
